<html>
<head>
  <title>mymodule.c</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="0000ff"><strong>#include <font color="#008000">&lt;Python.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;Numeric/arrayobject.h&gt;</font></strong></font>

<font color="0000ff"><strong>#include <font color="#008000">&lt;sys/types.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;stdio.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;stdlib.h&gt;</font></strong></font>


<strong>static</strong> <font color="#2040a0">PyObject</font> <font color="4444FF">*</font><font color="#2040a0">pyError</font><font color="4444FF">;</font>

<font color="#444444">/*
static PyObject *identity(PyObject * self, PyObject * args);
static PyObject *create_array(PyObject * self, PyObject * args);
*/</font>
<font color="0000ff"><strong>#include <font color="#008000">&quot;identity.h&quot;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&quot;create_array.h&quot;</font></strong></font>

<strong>static</strong> <font color="#2040a0">PyMethodDef</font> <font color="#2040a0">myMethods</font><font color="4444FF">[</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF"><strong>{</strong></font>
    <font color="4444FF"><strong>{</strong></font><font color="#008000">&quot;identity&quot;</font>,		<font color="#2040a0">identity</font>,			<font color="#2040a0">METH_VARARGS</font>,     	<font color="#2040a0">IDENTITY_DOC</font><font color="4444FF"><strong>}</strong></font>,
    <font color="4444FF"><strong>{</strong></font><font color="#008000">&quot;create_array&quot;</font>, <font color="#2040a0">create_array</font>, <font color="#2040a0">METH_VARARGS</font>,          <font color="#008000">&quot;create_array&quot;</font><font color="4444FF"><strong>}</strong></font>,
    <font color="4444FF"><strong>{</strong></font><font color="#2040a0">NULL</font>, <font color="#2040a0">NULL</font>, <font color="#FF0000">0</font>, <font color="#2040a0">NULL</font><font color="4444FF"><strong>}</strong></font>        <font color="#444444">/* Sentinel */</font>
<font color="4444FF"><strong>}</strong></font><font color="4444FF">;</font>


<strong>void</strong> <font color="#2040a0">init_myarray</font><font color="4444FF">(</font><strong>void</strong><font color="4444FF">)</font>
<font color="4444FF"><strong>{</strong></font>
	<font color="#2040a0">PyObject</font> <font color="4444FF">*</font><font color="#2040a0">m</font><font color="4444FF">;</font>
    <font color="#2040a0">PyObject</font> <font color="4444FF">*</font><font color="#2040a0">tmp</font><font color="4444FF">;</font>
	<font color="#2040a0">import_array</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
	<font color="#2040a0">m</font><font color="4444FF">=</font><font color="#2040a0">Py_InitModule</font><font color="4444FF">(</font><font color="#008000">&quot;_myarray&quot;</font>, <font color="#2040a0">myMethods</font><font color="4444FF">)</font><font color="4444FF">;</font>
	<font color="#2040a0">pyError</font> <font color="4444FF">=</font> <font color="#2040a0">PyErr_NewException</font><font color="4444FF">(</font><font color="#008000">&quot;myarray.error&quot;</font>, <font color="#2040a0">NULL</font>, <font color="#2040a0">NULL</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">Py_INCREF</font><font color="4444FF">(</font><font color="#2040a0">pyError</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">PyModule_AddObject</font><font color="4444FF">(</font><font color="#2040a0">m</font>, <font color="#008000">&quot;error&quot;</font>, <font color="#2040a0">pyError</font><font color="4444FF">)</font><font color="4444FF">;</font>
<font color="4444FF"><strong>}</strong></font>


</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
